package so.wy.servicecenter.businessbed.web.order;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;
import so.wy.servicecenter.base.exception.ServiceException;
import so.wy.servicecenter.base.exception.WebException;
import so.wy.servicecenter.base.frame.baseopt.BaseOptService;
import so.wy.servicecenter.base.frame.baseopt.BaseOptWeb;
import so.wy.servicecenter.base.frame.dao.PageData;
import so.wy.servicecenter.base.frame.web.webhand.WebExceptionHandler;
import so.wy.servicecenter.businessbed.dao.rdb.order.order.OrderDO;
import so.wy.servicecenter.businessbed.service.order.OrderService;
import so.wy.servicecenter.businessbed.service.order.dto.OrderDTO;


@Service
@Scope("prototype")
public class OrderWeb extends BaseOptWeb<OrderDTO> {
    @Autowired
    private OrderService orderService;

    @Override
    protected BaseOptService getOptService() {
        return orderService;
    }

    @WebExceptionHandler
    public PageData<OrderDO, OrderDTO> getRentUserOrders(Long userId, Integer curPage, Integer pageSize) throws WebException {
        curPage = curPage == null ?1:curPage;
        pageSize = pageSize == null ? 20: pageSize;

        try {
            return orderService.getRentUserOrders(userId, curPage, pageSize);
        } catch (ServiceException e) {
            throw exception(e);
        }
    }

    @WebExceptionHandler
    public OrderDTO getOrderInfoBySerial(String orderSerial){
        return orderService.getOrderInfoBySerial(orderSerial);
    }
}
